package com.manage.server.controller.admin;

import com.manage.dto.PositionDTO;
import com.manage.dto.add.PositionAddDTO;
import com.manage.dto.update.PositionUpdateDTO;
import com.manage.result.PageResult;
import com.manage.server.service.PositionService;
import com.manage.vo.PositionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.manage.result.Result;

@RestController
@RequestMapping("/position")
public class PositionController {

    @Autowired
    private PositionService positionService;

    @PostMapping
    public Result add(@RequestBody PositionAddDTO positionAddDTO) {
        positionService.save(positionAddDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        positionService.removeById(id);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody PositionUpdateDTO positionUpdateDTO) {
        positionService.updateById(positionUpdateDTO);
        return Result.success();
    }

    /**
     * 多项分类分页查询
     * @param positionDTO
     * @return
     */
    @PostMapping("/page")
    public PageResult<PositionVO> findPosition(@RequestBody PositionDTO positionDTO) {
        return positionService.findPositionByPage(positionDTO);
    }
}